home *** CD-ROM | disk | FTP | other *** search
/ Creative Computers / Creative Computers CD-ROM, Volume 1 (Legendary Design Technologies, Inc.)(1994).iso / shareware / fractals / sman / lib / smanlb.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  23KB  |  1,010 lines

  1. #include    "functions.h"
  2. #include    "exec/types.h"    /*Needed for SOFFSET macro*/
  3. #include    "exec/execbase.h"
  4. #include    "exec/tasks.h"
  5. #include    "exec/memory.h"
  6. #include    "exec/ports.h"
  7. #include    "clib/graphics_protos.h"
  8. #include    "graphics/view.h"
  9. #include    "graphics/gfx.h"
  10. #include    "graphics/gfxbase.h"
  11. #include    "graphics/gfxmacros.h"
  12. #include    "graphics/rastport.h"
  13. #include    "intuition/intuitionbase.h"
  14. #include    "intuition/intuition.h"
  15. #include    "intuition/preferences.h"
  16. #include    "libraries/dos.h"
  17. #include    "libraries/dosextens.h"
  18. #include    "stdio.h"
  19. #include    "exec/io.h"
  20. #include    "iff/iff.h"
  21. #include    "iff/ilbm.h"
  22.  
  23. double XWidth,XHeight,XCenter,YCenter,HWidth,HHeight,Factor,xRel,yRel,Zr,Zi,Z2;
  24. double Zr2,Zi2,Limit,FP7,Two;
  25. double LastX,LastY,LastLim,LastFactor;
  26. LONG    xtemp,ytemp,MaxCnt,CurCnt,XC,YC,LeftEdge,RightEdge,NearEdge,FarEdge;
  27. LONG    S1Height,S1Width,MltPlr;
  28. ULONG    *PlnPtr;
  29.  
  30. BPTR    FileHandle;
  31. #define    Pf_Size    0xe8
  32. #define    ScnFlg    0x1;
  33. #define    LacFlg    0x2;
  34. #define    ChdFlg    DefFlg | CHECKIT | CHECKED
  35. #define    ChkFlg    DefFlg | CHECKIT
  36.  
  37. CmpFlg    = MOUSEBUTTONS | MENUPICK;
  38. MyFlag     =    NOCAREREFRESH|REPORTMOUSE|BORDERLESS;
  39. MenFlg     =    MENUENABLED | MIDRAWN;
  40. DefFlg     =    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP;
  41.  
  42.  
  43. struct Library *DOSBase;
  44. struct GfxBase *GfxBase;
  45. struct IntuitionBase *IntuitionBase;
  46. struct ExecBase    *SysBase;
  47. struct    Gadget    *GadStuff;
  48. struct    NewScreen    ns;
  49. struct    NewWindow    nw;
  50. BYTE    CurrentXOffset;
  51. BYTE    CurrentYOffset;
  52. UBYTE    Title[] = "                          Julian Explorer";
  53. UBYTE    *WindowName;
  54. SHORT    SWidth,SHeight;
  55. USHORT    MyView,SUFlag,SysFlag,ScnSts,OvsChk,LacChk,LacMod,NLcChk,MenVal,NrmChk;
  56. struct    Screen    *IntScreen;
  57. struct    Screen    *WBScreen;
  58. struct    Window    *InfoWindow;
  59. struct    Window    *IntWindow;
  60. struct    MsgPort    *MyPort,*IntPort;
  61. struct    RastPort    *MyRasta,*WBRast,*CWRast;
  62. struct    ViewPort    VPorta,VPortb;
  63. struct    Preferences    MyNewPrefs,*CurPrefs;
  64. struct    Menu        Menu1,Menu2,Menu3,Menu4;
  65. struct    MenuItem    *MIStruct;
  66. struct    IntuiText    *ITStruct;
  67.  
  68. struct    MenuItem    MI11,MI12,MI13,MI14;
  69. struct    MenuItem    MI21,MI22,MI23,MI24;
  70. struct    MenuItem    MI31,MI32,MI33,MI34;
  71. struct    MenuItem    MI41,MI42,MI43,MI44;
  72. struct    IntuiText    IT11,IT12,IT13,IT14;
  73. struct    IntuiText    IT21,IT22,IT23,IT24;
  74. struct    IntuiText    IT31,IT32,IT33,IT34;
  75. struct    IntuiText    IT41,IT42,IT43,IT44;
  76.  
  77. struct    PLANEPTR    *PlanePtrA,*PlanePtrB;
  78. static    char    Err020[]    = "Sorry, but this Mandelbrot Generator requires both a 68881 and a 68020!";
  79. static    char    Err021[]    = "Use SManLb as a slow alternative!";
  80. static    char    Message[]     = "by David M. McKinstry";
  81. static    char    Mesag2[]    = "Copyright ";
  82. UBYTE    Mesag2b[]    = 0xa9;
  83. UBYTE    Comma[] = 0x2c;
  84. static    char    Mesag2c[]    = " 1989-91";
  85. static    char    Mesag3[]    = "System Hardware: ";
  86. static    char    Mesag4[]    = "Use the menu options on the Custom Screen to change the following parameters!";
  87. static    char    Mesag5[]    = "Click on the Close Gadget to bring the Custom Screen forward!";
  88. static    char    Mesag6[]    = "(Note:  This window won't be closed, just hidden.)";
  89. static    char    Mesag7[]    = "To return to this WorkBench Screen, select 'About' from the SManLb menu!";
  90. static    char    ScrMsg[]    = "Screen center is at ";
  91. static    char    ChpMsg[]    = "Chip Memory Free = ";
  92. static    char    ChpEnd[]    = "                ";
  93. static    char    FstMsg[]    = "Fast Memory Free = ";
  94. static    char    FstEnd[]    = "                ";
  95. static    char    WdtMsg[]    = "Screen Width =  ";
  96. static    char    WdtEnd[]    = "        ";
  97. static    char    HgtMsg[]    = "Screen Height = ";
  98. static    char    HgtEnd[]    = "        ";
  99. static    char    MagMsg[]    = "Magnification = ";
  100. static    char    MagEnd[]    = "                  ";
  101. static    char    XPos[]        = "x = ";
  102. static    char    XPsEnd[]    = "                  ";
  103. static    char    YPos[]        = "y = ";
  104. static    char    YPsEnd[]    = "                  ";
  105. static    char    CntMsg[]    = "Maximum Count = ";
  106. static    char    CntEnd[]    = "        ";
  107. static    char    HavMsg[]    = "You have at least a 68020 and 68881.  Why not use SManCP?";
  108. static    char    StrngBuffer[200];
  109. SHORT    VertPos;
  110. USHORT    CTable[] = {0,0xf00,0xff0,0x3f8,0x5ea,0xf3a,0x0de,0xf80,0x9f0,0x7df,0x69f,
  111.                     0x00f,0xf2e,0xc0e,0x60e,0x607};
  112.  
  113. SHORT    PolyTab[10];
  114. SHORT    *PolyPnt;
  115. SHORT DeltaX,DeltaY;
  116. SHORT    x1,y1,x2,y2;
  117. ULONG    IMClass;
  118.  
  119. ScanOn()
  120. {
  121.     NrmChk = ChkFlg;
  122.     OvsChk = ChdFlg;
  123.     SWidth = 704;
  124.     SHeight = 478;
  125.     S1Width = 703;
  126.     S1Height = 477;
  127.     XC = 352;
  128.     YC = 239;
  129.     NearEdge = 0;
  130.     LeftEdge = 0;
  131.     RightEdge = 704;
  132.     FarEdge = 478;
  133.     ScnSts = 1;    /* Indicate overscan on */
  134. }
  135.  
  136. ScnOff()
  137. {
  138.     NrmChk = ChdFlg;
  139.     OvsChk = ChkFlg;
  140.     SWidth = 640;
  141.     SHeight = 400;
  142.     S1Width = 639;
  143.     S1Height = 399;
  144.     XC = 320;
  145.     YC = 199;
  146.     NearEdge = 0;
  147.     LeftEdge = 0;
  148.     RightEdge = 640;
  149.     FarEdge = 400;
  150.     ScnSts = 0;    /* Change to no overscan */
  151. }
  152.  
  153. LaceOff()
  154. {
  155.     MyView = HIRES;
  156.     LacChk = ChkFlg;
  157.     NLcChk = ChdFlg;
  158.     LacMod = 0;
  159.     SHeight = SHeight/2;
  160.     S1Height = SHeight;
  161.     --S1Height;
  162.     FarEdge = FarEdge/2;
  163. }
  164.  
  165. LaceOn()
  166. {
  167.     MyView = HIRES | LACE;
  168.     LacChk = ChdFlg;
  169.     NLcChk = ChkFlg;
  170.     LacMod = 1;
  171. }
  172. ScnSet()
  173. {
  174.     if (SUFlag & 0x2)    {
  175.         LaceOn();
  176.         }
  177.     else LaceOff();
  178. }
  179.  
  180. ViewSet()
  181. {
  182.     if (SUFlag & 0x1)    {    /* See if Overscan flag set */
  183.         ScanOn();
  184.         ScnSet();
  185.         }
  186.     else {
  187.         ScnOff();
  188.         ScnSet();
  189.         }
  190. }
  191.  
  192. SetLim()
  193. {
  194.     Limit = Two*Factor;
  195.     Limit = Limit*Limit;
  196. }
  197.  
  198. InitPar()
  199. {
  200.     XWidth = SWidth;
  201.     XHeight = SHeight;
  202.     HWidth = XC;
  203.     XCenter = XC;
  204.     HHeight = YC;
  205.     YCenter = YC;
  206.     SetLim();
  207. }
  208.  
  209. HasFast()
  210. {
  211.     ViewSet();
  212.     Factor = MltPlr;
  213.     Factor = MltPlr;
  214.     InitPar();
  215. }
  216.  
  217.  
  218. void ITInit(Item,NamePtr)
  219. struct    IntuiText    *Item;
  220. UBYTE    *NamePtr;
  221. {
  222.     Item -> IText = NamePtr;
  223.     Item -> BackPen = 3;
  224.     Item -> FrontPen = 5;
  225.     Item -> DrawMode = JAM1;
  226. }
  227. MIInit(Item,NxtItem,TEdge,Cmd,ITItem,Width)
  228. struct    MenuItem    *Item,*NxtItem;
  229. APTR    ITItem;
  230. SHORT    TEdge,Width;
  231. BYTE    Cmd;
  232. {
  233.     Item -> Command = Cmd;
  234.     Item -> TopEdge = TEdge;
  235.     Item -> NextItem = NxtItem;
  236.     Item -> ItemFill = (APTR)ITItem;
  237.     Item -> Flags = (USHORT)DefFlg;
  238.     Item -> Height = 9;
  239.     Item -> Width = Width;
  240. }
  241.  
  242. void MenuInit(MenuStruct,NxtMenu,NamePtr,LEdge,MWidth)
  243. struct Menu    *MenuStruct,*NxtMenu;
  244. SHORT    LEdge,MWidth;
  245. BYTE    *NamePtr;
  246. {
  247.     MenuStruct -> NextMenu = NxtMenu;
  248.     MenuStruct -> Width = MWidth;
  249.     MenuStruct -> Height = 9;
  250.     MenuStruct -> LeftEdge = LEdge;
  251.     MenuStruct -> TopEdge = 0;
  252.     MenuStruct -> MenuName = NamePtr;
  253.     MenuStruct -> Flags = MenFlg;
  254.  
  255. }
  256.  
  257. void ScreenSet()
  258. {
  259. SHORT    MWidth,MHeight,LEdge,TEdge;
  260. UBYTE    MICommand;
  261. struct    Menu    *MenStrct;
  262. BOOL Test;
  263. ns.LeftEdge    =    0;
  264. ns.TopEdge     =   0;        /*Was 20 */
  265. ns.Width       =  SWidth;
  266. ns.Height      =  SHeight;
  267. ns.DetailPen   =   0;
  268. ns.BlockPen    =   1;
  269. ns.Depth       =   4;
  270. ns.ViewModes   =   MyView;
  271.  
  272.     IntScreen = (struct Screen *)OpenScreen( &ns );
  273.     PlanePtrA = (struct PLANEPTR *)(IntScreen -> BitMap.Planes);
  274.     MyRasta = &(IntScreen -> RastPort);
  275.     VPorta = IntScreen -> ViewPort;
  276.     LoadRGB4(&VPorta,&CTable[0],16);
  277.     if (ScnSts)    {
  278.         MyNewPrefs.ViewXOffset = 0xde;
  279.         MyNewPrefs.ViewYOffset = 0xed;
  280.         }
  281.     else    {
  282.         MyNewPrefs.ViewXOffset = CurrentXOffset;
  283.         MyNewPrefs.ViewYOffset = CurrentYOffset;
  284.         }
  285.     SetPrefs(&MyNewPrefs,Pf_Size,FALSE);
  286.  
  287.     nw.Title = NULL;
  288. nw.LeftEdge        =    0;
  289. nw.TopEdge        =    0;
  290. nw.Width        =    SWidth;
  291. nw.Height        =    SHeight;
  292. nw.DetailPen    =    5;
  293. nw.BlockPen        =    2;
  294. /*nw.IDCMPFlags    =    GADGETUP | MENUPICK;*/
  295. nw.IDCMPFlags    =    CmpFlg;
  296. nw.Type            =    CUSTOMSCREEN;
  297. nw.Flags        =    MyFlag;    ACTIVATE | SMART_REFRESH;
  298. nw.FirstGadget    =    NULL;
  299. nw.CheckMark    =    NULL;
  300. nw.Screen        =    IntScreen;
  301. nw.BitMap        =    NULL;
  302. nw.MinWidth        =    320;
  303. nw.MinHeight    =    100;
  304. nw.MaxWidth        =    SWidth;
  305. nw.MaxHeight    =    SHeight;
  306.  
  307.     IntWindow = (struct Window *)OpenWindow( &nw );
  308.  
  309. /* Get associated information about Int window */
  310. /*    GadStuff = IntWindow -> FirstGadget;*/
  311.     CWRast = IntWindow -> RPort;
  312.     SetRast(CWRast,0);
  313.     IntPort    = IntWindow -> UserPort;
  314.  
  315. /*    Template is 
  316.     MenuInit(&Menu1,&Menu2,"Strng",LEdge,MWidth);
  317.         */
  318.  
  319.     MenuInit(&Menu1,&Menu2,"SManLb",20,100);
  320.     Menu1.FirstItem = &MI11;
  321.     MIInit(&MI11,&MI12,0,0x41,&IT11,150);    
  322.     MIInit(&MI12,&MI13,9,0x52,&IT12,150);
  323.     MIInit(&MI13,&MI14,18,0x53,&IT13,150);
  324.     MIInit(&MI14,0,27,0x51,&IT14,150);    
  325.  
  326.     ITInit(&IT11,"About");
  327.     ITInit(&IT12,"Redraw(Same P)");
  328.     ITInit(&IT13,"Save");
  329.     ITInit(&IT14,"Quit");
  330.  
  331.     MenuInit(&Menu2,&Menu3,"View Mode",180,130);
  332.     Menu2.FirstItem = &MI21;
  333.     MIInit(&MI21,&MI22,0,0x4c,&IT21,150);    
  334.     MIInit(&MI22,&MI23,9,0x43,&IT22,150);
  335.     MIInit(&MI23,&MI24,18,0x4d,&IT23,150);
  336.     MIInit(&MI24,0,27,0x4e,&IT24,150);    
  337.  
  338.     ITInit(&IT21,"   Lace On");
  339.     ITInit(&IT22,"   Lace Off");
  340.     ITInit(&IT23,"   Ove